Replace array element at index with the ref value on the stack